﻿using System;
using System.Windows.Forms;

namespace Crawler
{
    public partial class Crawler : Form
    {
        public Crawler()
        {
            InitializeComponent();
        }

        private async void Crawl_Click(object sender, EventArgs e)
        {
            Button button = sender as Button;
            button.Enabled = false;
            button.Text = "正在爬";
            await foreach (string res in SimpleCrawler.Crawl(url.Text))
            {
                textBox.AppendText(res);
                textBox.ScrollToCaret();
            }
            button.Enabled = true;
            button.Text = "开始爬";
        }

        private void Url_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter && Crawl.Enabled == true)
            {
                Crawl.PerformClick();
            }
        }
    }
}
